define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        //餐饮生活类型列表
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'life/life/index',
                    add_url: 'life/life/add',
                    del_url: 'life/life/del',
                    multi_url: 'life/life/multi',
                    table: 'type',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'type_id',
                sortName: 'type_id',
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'type_id', title:'ID', operate: false},
                        {field: 'type_name', title: '分类名称', operate: false},
                        {field: 'is_delete', title: '是否显示', operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false,
                commonSearch: false
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        amoy_list: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'life/life/amoy_list',
                    add_url: 'life/life/amoy_add',
                    edit_url: 'life/life/amoy_edit',
                    del_url: 'life/life/amoy_del',
                    table: 'amoy',
                }
            });
            var types = JSON.parse($(':hidden[name=types]').val());
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'amoy_id',
                sortName: 'amoy_id',
                columns: [
                    [
                        {field: 'amoy_id', title: 'ID', operate:false},
                        {field: 'user_id', title: '用户'},
                        {field: 'title', title: '标题', operate:false},
                        {field: 'type_name', title: '信息分类',formatter: Table.api.formatter.status, searchList: types, style: 'min-width:100px;'},
                        {field: 'add_time', title: '创建时间',formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},
                        {field: 'is_show', title: '是否显示',operate:false},
                        {field: 'is_push', title: '是否推送',operate:false},
                        {field: 'content', title: '内容', operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name:'url',
                                    text:'',
                                    icon: 'fa fa-anchor',
                                    classname: 'btn btn-info btn-xs btn-dialog',
                                    url: 'wx/amoy/mobile_url'
                                }
                            ]}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        amoy_add: function () {
            Controller.api.bindevent();
        },
        amoy_edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});